package com.kuizii.common;

import org.springframework.cloud.client.ServiceInstance;

import java.io.Serializable;
import java.net.URI;
import java.util.Map;


/**
 * @author renxiaodong
 */
public class LiteServiceInstance implements   ServiceInstance , Serializable {


    public void setServiceId(String serviceId) {
        this.serviceId = serviceId;
    }

    String serviceId;

    String host;

    Integer port;

    String clusterId;

    public LiteServiceInstance(String host, Integer port) {
        this.host = host;
        this.port = port;
    }



    public String getClusterId() {
        return clusterId;
    }

    public void setClusterId(String clusterId) {
        this.clusterId = clusterId;
    }

    @Override
    public String getServiceId() {
        return serviceId;
    }

    @Override
    public String getHost() {
        return host;
    }

    @Override
    public int getPort() {
        return port;
    }

    @Override
    public boolean isSecure() {
        return false;
    }

    public URI getUri(ServiceInstance instance) {
        String scheme = instance.isSecure() ? "https" : "http";
        String uri = String.format("%s://%s:%s", scheme, instance.getHost(), instance.getPort());
        return URI.create(uri);
    }

    @Override
    public URI getUri() {
        return getUri(this);
    }

    @Override
    public Map<String, String> getMetadata() {
        return null;
    }
}
